package com.zhj.condition;

import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;

import java.util.Map;

/**
 * 自定义条件
 */

public class OnBeanCondition implements Condition {
	@Override
	public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
		ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
		if (metadata.isAnnotated(ConditionOnBean.class.getName())) {
			Map<String, Object> annotationAttributes = metadata.getAnnotationAttributes(ConditionOnBean.class.getName());
			/*Class[] values = (Class[]) annotationAttributes.get("value");
			for (Class value : values) {
				System.out.println("value："+value.getName());
				beanFactory.getBeanDefinition(value.getName());
			}*/
		}
		return true;
	}
}
